package com.x.erp.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.x.erp.model.Gate;
import com.x.erp.rpc.CarRpcService;
import com.x.erp.rpc.GateRpcService;
import com.x.framework.controller.BaseController;
import com.x.framework.controller.ResultCode;
import com.x.framework.controller.ResultModel;
import org.apache.commons.lang.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * 道闸出入车辆信息
 */
@RestController
@RequestMapping("/gate")
public class GateController extends BaseController {

	@Reference
	private GateRpcService gateRpcService;// 道闸信息服务

	@Reference
	private CarRpcService carRpcService;// 车辆信息服务

	/**
	 * 查询道闸信息列表
	 * @param
	 * @return
	 */
	@RequestMapping(value = "/getGateList", method = { RequestMethod.POST, RequestMethod.GET })
	public ResultModel getGateList(Gate gate) {
		return new ResultModel(ResultCode.RESULT_SUCCESS, "查询成功", gateRpcService.selectGateList(gate));
	}

	/**
	 * 查询道闸信息数量
	 * @param
	 * @return
	 */
	@RequestMapping(value = "/getGateNum", method = { RequestMethod.POST, RequestMethod.GET })
	public ResultModel getGateNum(Gate gate) {
		Map<String, Object> res = new HashMap<>();
		res.put("total", gateRpcService.selectGateNum(gate));
		return new ResultModel(ResultCode.RESULT_SUCCESS, "查询成功", res);
	}

	/**
	 * 新增道闸信息
	 * @param
	 * @return
	 */
	@RequestMapping(value = "/insertGate", method = { RequestMethod.POST, RequestMethod.GET })
	public ResultModel insertGate(Gate gate) {
		if (gate == null) {
			return new ResultModel(ResultCode.RESULT_FAIL, "道闸信息不能为空！");
		}
		if (StringUtils.isEmpty(gate.getGateCode())) {
			return new ResultModel(ResultCode.RESULT_FAIL, "道闸编号不能为空！");
		}
		return new ResultModel(ResultCode.RESULT_SUCCESS, "插入成功！", gateRpcService.insertGate(gate));
	}

}
